package com.yndsoft.jc.ui.memberpage.myorder;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.yndsoft.jc.R;
import com.yndsoft.jc.model.OrderDet;
import com.yndsoft.jc.netutils.AppUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by hasee on 2017/12/8.
 */

public class OrderDetailAdapter extends BaseAdapter {

    private Context context;
    private LayoutInflater inflater;
    private List<OrderDet> datas = new ArrayList<>();

    public OrderDetailAdapter(Context context) {
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    public void setDatas(List<OrderDet> datas) {
        this.datas.clear();
        this.datas.addAll(datas);
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {
        OrderDetailViewHolder holder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.layout_my_order_copy, null);
            holder = new OrderDetailViewHolder();
            holder.product_name = convertView.findViewById(R.id.product_name);
            holder.order_detail_check1 = convertView.findViewById(R.id.order_detail_check1);
            holder.order_detail_check2 = convertView.findViewById(R.id.order_detail_check2);
            holder.order_detail_check3 = convertView.findViewById(R.id.order_detail_check3);
            holder.order_detail_pricep = convertView.findViewById(R.id.order_detail_pricep);
            convertView.setTag(holder);
        } else {
            holder = (OrderDetailViewHolder) convertView.getTag();
        }

        AppUtils.setText(holder.product_name, datas.get(position).getName());
        AppUtils.setText(holder.order_detail_check1, datas.get(position).getProductattribute().getProject());
        AppUtils.setText(holder.order_detail_check2, datas.get(position).getProductattribute().getMethod());
        AppUtils.setText(holder.order_detail_check3, datas.get(position).getProductattribute().getStandard());
        AppUtils.setText(holder.order_detail_pricep, datas.get(position).getPayprice() + "");
        return convertView;
    }

    class OrderDetailViewHolder {
        TextView product_name, order_detail_check1, order_detail_check2, order_detail_check3, order_detail_pricep;
    }
}
